//搜索,导出
$('#search-btn,#export-btn').click(function(){
	var btnId = $(this).attr("id");
	var trademarkSn = parseInt($('#trademark_sn').val());
	var trademarkStatus = $('#trademarkStatus').val();
	var agentId = $('#agentId').val();
	var saleStatus = $('#saleStatus').val();
	var imageStatus = $('#imageStatus').val();
	var startTime = $('#startTime').val();
	var endTime = $('#endTime').val();
	if(startTime && endTime){
		if(startTime > endTime){
			errmsg('开始日期不能大于结束日期');
			return;
		}
	}
	var reqUrl = "/member/trademarksmanage";
	if( btnId == 'export-btn' ){
		reqUrl += "/ac/export";
	}
	reqUrl +=( trademarkSn ? "/trademarkSn/" + trademarkSn : "" )
	reqUrl +=( trademarkStatus ? "/trademarkStatus/" + trademarkStatus : "" )
	reqUrl +=( saleStatus ? "/saleStatus/" + saleStatus : "")
	reqUrl +=( imageStatus ? "/imageStatus/" + imageStatus : "")
	reqUrl +=( agentId ? "/agentId/" + agentId : "")
	reqUrl +=( startTime ? "/ts/" + startTime : "" )
	reqUrl +=( endTime ? "/te/" + endTime : "" ) +".html";
	window.location.href = reqUrl;
});
// 全选
$('input[name="checkall"]').click(function(){
	if(this.checked){
		$('input:checkbox[name="trademark"]').prop("checked", true);
	}else{
		$('input:checkbox[name="trademark"]').prop("checked", false);
	}
});
//批量操作
$("#batch-action-btn").click(function (){
	var ids = new Array();
	var i = 0;
	$("input:checkbox[name='trademark']:checked").each(function(){
		var id = parseInt($(this).val());
		var reg = /^[1-9][0-9]*$/;
		if(reg.test(id)){
			ids[i] = $(this).val();
			i++;
		}
	})
	if( ids.length < 1 ){
		return errmsg("请选择商标!");
	}
	jdbox.iframe('/member/trademarksbatchaction.html',{ac:"dispaly",ids:ids.join(",")});
});
//单个商标编辑
$(".editTrdemark").click(function (){
	$(this).blur();
	var id = $(this).attr("trademarkid");
	var ids = new Array();
	ids[0] = id;
	if( ids.length < 1){
		return errmsg("参数不正确");
	}
	jdbox.iframe('/member/trademarksbatchaction.html',{ac:"dispaly",ids:ids.join(",")});
});
//删除商标
$(".delTrdemark").click(function (){
	$(this).blur();
	var id = $(this).attr("trademarkid");
	$.ajax({
		url   : '/member/deltrademark',
		data  :{id: id},
		cache : false,
		async : false,
		type  : "POST",
		dataType : 'json',
		success  : function (result){
			if(result.status == 0){
				return errmsg(result.msg);
			}else{
				window.location.reload();
				return false;
			}
		}
	});
});

//重新生成缩略图
$(".resetColorImage").click(function (){
	$(this).blur();
	var id = $(this).attr("trademarkid");
	$.ajax({
		url   : '/member/resetColorImage',
		data  :{id: id},
		cache : false,
		async : false,
		type  : "POST",
		dataType : 'json',
		success  : function (result){
			if(result.status == 0){
				return errmsg(result.msg);
			}else{
				window.location.reload();
				return false;
			}
		}
	});
});


